package com.sky.service.Impl;

import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.mapper.DishFlavorMapper;
import com.sky.mapper.DishMapper;
import com.sky.mapper.UserDishMapper;
import com.sky.service.UserDishService;
import com.sky.vo.DishVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class UserDishServiceImpl implements UserDishService {

    @Autowired
    private UserDishMapper userDishMapper;

    @Autowired
    private DishFlavorMapper dishFlavorMapper;

    @Override
    public List<DishVO> showDish(Long id) {

        List<DishVO> dishVOS = userDishMapper.showByCateId(id);

        for (DishVO d : dishVOS) {
            Long id1 = d.getId();
            List<DishFlavor> df = dishFlavorMapper.getDishFlavor(id1);
            d.setFlavors(df);
        }

        List<DishVO> collect = dishVOS.stream().filter(s -> s.getStatus() == 1).collect(Collectors.toList());

        return collect;
    }
}
